package com.xydtech.ecard.merchant.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.merchant.domain.EcardMerchantVisitInfo;
import com.xydtech.ecard.merchant.service.IEcardMerchantVisitInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电子名片商户拜访记录Controller
 *
 * @author xydtech
 * @date 2023-08-01
 */
@Controller
@RequestMapping("/merchant/info/visit")
public class EcardMerchantVisitInfoController extends BaseController
{
    private String prefix = "merchant";

    @Autowired
    private IEcardMerchantVisitInfoService ecardMerchantVisitInfoService;

    //@RequiresPermissions("merchant:visit:view")
    @GetMapping("/{merchantId}/{merchantType}")
    public String visit(@PathVariable("merchantId") String merchantId, @PathVariable("merchantType") String merchantType, ModelMap mmap)
    {
        mmap.put("merchantId", merchantId);
        mmap.put("merchantType", merchantType);
        return prefix + "/visit";
    }

    /**
     * 查询电子名片商户拜访记录列表
     */
    //@RequiresPermissions("merchant:visit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardMerchantVisitInfo ecardMerchantVisitInfo)
    {
        startPage();
        List<EcardMerchantVisitInfo> list = ecardMerchantVisitInfoService.selectEcardMerchantVisitInfoList(ecardMerchantVisitInfo);
        return getDataTable(list);
    }

    /**
     * 导出电子名片商户拜访记录列表
     */
    //@RequiresPermissions("merchant:visit:export")
    @Log(title = "电子名片商户拜访记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardMerchantVisitInfo ecardMerchantVisitInfo)
    {
        List<EcardMerchantVisitInfo> list = ecardMerchantVisitInfoService.selectEcardMerchantVisitInfoListByExport(ecardMerchantVisitInfo);
        ExcelUtil<EcardMerchantVisitInfo> util = new ExcelUtil<EcardMerchantVisitInfo>(EcardMerchantVisitInfo.class);
        return util.exportExcel(list, "电子名片商户拜访记录数据");
    }

    /**
     * 新增电子名片商户拜访记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电子名片商户拜访记录
     */
    @RequiresPermissions("merchant:visit:add")
    @Log(title = "电子名片商户拜访记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardMerchantVisitInfo ecardMerchantVisitInfo)
    {
        return toAjax(ecardMerchantVisitInfoService.insertEcardMerchantVisitInfo(ecardMerchantVisitInfo));
    }

    /**
     * 修改电子名片商户拜访记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EcardMerchantVisitInfo ecardMerchantVisitInfo = ecardMerchantVisitInfoService.selectEcardMerchantVisitInfoById(id);
        mmap.put("ecardMerchantVisitInfo", ecardMerchantVisitInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子名片商户拜访记录
     */
    @RequiresPermissions("merchant:visit:edit")
    @Log(title = "电子名片商户拜访记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardMerchantVisitInfo ecardMerchantVisitInfo)
    {
        return toAjax(ecardMerchantVisitInfoService.updateEcardMerchantVisitInfo(ecardMerchantVisitInfo));
    }

    /**
     * 删除电子名片商户拜访记录
     */
    @RequiresPermissions("merchant:visit:remove")
    @Log(title = "电子名片商户拜访记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ecardMerchantVisitInfoService.deleteEcardMerchantVisitInfoByIds(ids));
    }


    /**
     * 电子名片商户拜访状态修改
     * @param ecardMerchantVisitInfo
     * @return
     */
    @RequiresPermissions("ecard:config:homePage:edit")
    @Log(title = "电子名片商户拜访状态修改", businessType = BusinessType.UPDATE)
    @PostMapping("/changeStatus")
    @ResponseBody
    public AjaxResult changeStatus(EcardMerchantVisitInfo ecardMerchantVisitInfo) {
        return toAjax(ecardMerchantVisitInfoService.updateEcardMerchantVisitInfo(ecardMerchantVisitInfo));
    }
}
